package com.api.fc;
//会议归档写建模的api

import com.alibaba.fastjson.JSONObject;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.upgradetool.wscheck.Util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Path("/fc_zh_pms")
public class get_zh_pms_detail {
    //    private Logger logger = LoggerFactory.getLogger(Hygdxjm.class);
    private RecordSet rs = new RecordSet();


    @GET
    @Path("/get_params")
    @Produces(MediaType.APPLICATION_JSON)
    public String get_mains(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        JSONObject errorobj = new JSONObject();
        RecordSet rs = new RecordSet();

        String param_name=request.getParameter("param_name");
        String mobile=request.getParameter("mobile");


        String endString="[";

        String sql = "" ;

        if("ycly".equals(param_name)||"KDBM".equals(param_name)||"FXGX".equals(param_name)){
            sql=
                    "select*from ("+
                            "        select o1.fieldname 字段代号,o1.labelname 字段名称,cast(o2.selectvalue as varchar(100)) selectvalue,o2.selectname ,case when isnull(o2.cancel,0)=0 then '是' else '否' end  isnot_inuse     from ("+
                            "                select  o2.labelname,o1.fieldname,o1.id  from ("+
                            "                        select id,fieldname,fieldlabel from workflow_billfield   where billid=-61"+
                            "                )o1,htmllabelinfo o2 where o2.indexid=o1.fieldlabel and o2.languageid=7"+
                            "        )o1,workflow_selectitem o2 where o1.id=o2.fieldid"+
                            ")o1  where 1=1 and o1.字段代号 ='"+param_name+"'";
        }else if("jxxz".equals(param_name)){
            sql="select 'jxxz','机型(选择)',symc,symc,case when isnull(sfsy,0)=0 then '是' else '否' end  isnot_inuse from uf_oled_jixing  ";
        }else if("hrm".equals(param_name) ){
            sql="select '人员',id,lastname name ,workcode,case when status in (0,1,2,3) then '在职' else '离职' end status,managerid  from HrmResource   ";
        }else if( "hrm_bymobile".equals(param_name)){
            sql="select '人员',id,lastname name ,workcode,case when status in (0,1,2,3) then '在职' else '离职' end status,managerid  from HrmResource   where mobile='"+mobile+"'";
        }
        rs.executeSql(sql);
        while(rs.next()){
            String  selectvalue= Util.null2String(rs.getString("selectvalue"));
            String  selectname= Util.null2String(rs.getString("selectname"));
            String  isnot_inuse= Util.null2String(rs.getString("isnot_inuse"));

            String  symc= Util.null2String(rs.getString("symc"));

            String  id= Util.null2String(rs.getString("id"));
            String  name= Util.null2String(rs.getString("name"));
            String  workcode= Util.null2String(rs.getString("workcode"));
            String  status= Util.null2String(rs.getString("status"));
            String  managerid= Util.null2String(rs.getString("managerid"));
            String  departmentid= Util.null2String(rs.getString("departmentid"));

            String line="{";

            if("ycly".equals(param_name)||"KDBM".equals(param_name)||"FXGX".equals(param_name)){
                line+="\"selectvalue\":\""+selectvalue+"\"";
                line+=",\"selectname\":\""+selectname+"\"";
                line+=",\"isnot_inuse\":\""+isnot_inuse+"\"";
            }else if("jxxz".equals(param_name)){
               // sql="select 'jxxz','机型(选择)',symc,symc,case when isnull(sfsy,0)=0 then '是' else '否' end  isnot_inuse from uf_oled_jixing  ";
                line+="\"symc\":\""+symc+"\"";
                line+=",\"isnot_inuse\":\""+isnot_inuse+"\"";
            }else if("hrm".equals(param_name)||"hrm_bymobile".equals(param_name)){
                //sql="select '人员',id,lastname name ,workcode,case when status in (0,1,2,3) then '在职' else '离职' end status,managerid  from HrmResource   ";
                line+="\"id\":\""+id+"\"";
                line+=",\"name\":\""+name+"\"";
                line+=",\"workcode\":\""+workcode+"\"";
               // line+=",\"managerid\":\""+managerid+"\"";

                line+=",\"status\":\""+status+"\"";
            }

            line+="}";

            if(endString.equals("[")){
                endString+=line;
            }else{
                endString+=","+line;
            }
        }



        endString=endString+']';


        Map<String, Object> data = new HashMap<String, Object>();
        data.put("result",endString);
        String json = JSONObject.toJSONString(data);
        return json;
    }






}